package com.zmn.oms.common.constant;

import com.google.common.collect.Lists;
import com.zmn.common.dictionary.DictModel;
import com.zmn.dms.common.enums.DiscountTypeEnums;

import java.util.List;

/**
 * 类描述：优惠
 * @author heciqi
 * @date 2020/6/8 14:31
 */
public class DiscountConsts {

    /**
     * 渠道优惠券批次id
     */
    public final static int BATCH_ID_CHANNEL_DISCOUNT = 20001;

    /**
     * 特殊优惠券批次id（总公司承担）
     */
    public final static int BATCH_ID_FREE_DISCOUNT_HQ_COMPANY = 20002;

    /**
     * 特殊优惠券批次id2(子公司承担)
     */
    public final static int BATCH_ID_FREE_DISCOUNT_SUB_COMPANY = 20307;

    /**
     * 后台人工优惠批次id（OMS定义，方便优惠控制）
     */
    public final static int BATCH_ID_ARTIFICIAL_STAFF = 100001;

    /**
     * 工程师人工优惠批次id（OMS定义，方便优惠控制）
     */
    public final static int BATCH_ID_ARTIFICIAL_MASTER = 100002;


    /**
     * 人工优惠-工程师
     */
    public final static int ARTIFICIAL_DISCOUNT_TYPE_MASTER = 1;

    /**
     * 人工优惠-后台
     */
    public final static int ARTIFICIAL_DISCOUNT_TYPE_STAFF = 2;
    /**
     * 人工优惠-全免
     */
    public final static int ARTIFICIAL_DISCOUNT_TYPE_FREE = 3;


    /**
     * 优惠券类型
     */
    public final static int DISCOUNT_CATEG_COUPON = 31;

    /**
     * 代金券
     */
    public final static int DISCOUNT_CATEG_CASH_COUPON = 32;

    /**
     * 人工优惠类型  com.zmn.dms.common.enums.DiscountTypeEnums
     */
    public final static int DISCOUNT_CATEG_ARTIFICIAL = 12;

    /**
     * 促销优惠类型  com.zmn.dms.common.enums.DiscountTypeEnums
     */
    public final static int DISCOUNT_CATEG_PROM = 11;
    /**
     * 渠道优惠类型  com.zmn.dms.common.enums.DiscountTypeEnums
     */
    public final static int DISCOUNT_CATEG_CHANNEL = 51;
    /**
     * 特殊优惠类型  com.zmn.dms.common.enums.DiscountTypeEnums
     */
    public final static int DISCOUNT_CATEG_SPECIAL = 52;

    /**
     * 待核销
     */
    public final static int WRITE_OFF_STATUS_WAIT = 10;

    /**
     * 已核销
     */
    public final static int WRITE_OFF_STATUS_DO = 20;

    /**
     * 已作废
     */
    public final static int WRITE_OFF_STATUS_VOID = 30;

    /**
     * 转换到工单优惠类型
     * @return
     */
    public static int convertToOMSDiscountType(Integer dmsDiscountType) {
        if (dmsDiscountType == null) {
            return 0;
        }

        // DMS优惠方式：1折扣，2满减
        int intValue = dmsDiscountType.intValue();
        switch (intValue) {
            case 1:
                return OrderConsts.ORDER_DISCOUNT_TYPE_DISCOUNT;
            case 2:
                return OrderConsts.ORDER_DISCOUNT_TYPE_FULFILL_FREE;
            default:
                return 0;
        }
    }

    /**
     * 转换到营销优惠类型
     * @return
     */
    public static int convertToDMSDiscountType(Integer omsDiscountType) {
        if (omsDiscountType == null) {
            return 0;
        }

        // DMS优惠方式：1折扣，2满减
        int intValue = omsDiscountType.intValue();
        switch (intValue) {
            case OrderConsts.ORDER_DISCOUNT_TYPE_DISCOUNT:
                return 1;
            case OrderConsts.ORDER_DISCOUNT_TYPE_FULFILL_FREE:
                return 2;
            default:
                return 0;
        }
    }


    public static int convertOperateIdToAffType(Integer operaterId) {
        if (operaterId == null) {
            return ARTIFICIAL_DISCOUNT_TYPE_STAFF;
        }
        int intValue = operaterId.intValue();
        switch (intValue) {
            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_ONE:
//            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_TWO:
//            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_THREE:
                return ARTIFICIAL_DISCOUNT_TYPE_STAFF;
            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_FREE:
                return ARTIFICIAL_DISCOUNT_TYPE_FREE;
            default:
                return ARTIFICIAL_DISCOUNT_TYPE_STAFF;
        }
    }

    public static TriggerAmountChangeEnum convertOperateIdToTriggerOrderAmountEnum(Integer operaterId) {
        if (operaterId == null) {
            return TriggerAmountChangeEnum.ARTIFICIAL_OPERATE_DISCOUNT;
        }
        int intValue = operaterId.intValue();
        switch (intValue) {
            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_ONE:
//            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_TWO:
//            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_LEVEL_THREE:
                return TriggerAmountChangeEnum.ARTIFICIAL_OPERATE_DISCOUNT;
            case OrderConsts.ORDER_OP_TYPE_DISCOUNT_FREE:
                return TriggerAmountChangeEnum.ARTIFICIAL_OPERATE_FREE_DISCOUNT;
            default:
                return TriggerAmountChangeEnum.ARTIFICIAL_OPERATE_DISCOUNT;
        }
    }

    /**
     * 优惠分类
     *
     * @return
     */
    public static List<DictModel> getDiscountCategList() {
        List<DictModel> items = Lists.newArrayList();
        for (DiscountTypeEnums discountTypeEnums : DiscountTypeEnums.values()) {
            items.add(new DictModel(discountTypeEnums.getSubType(), discountTypeEnums.getSubName()));
        }
        return items;
    }

    /**
     * 优惠类型转换到支付凭证的金额类型
     * @param discountCateg
     * @return
     */
    public static Integer getDiscountCateToAmountType(Integer discountCateg) {
        String amountType = "20" + discountCateg;
        return Integer.valueOf(amountType);
    }

    /**
     * 是否为优惠金额类型
     *
     * @param amountType
     * @return
     */
    public static boolean isDiscountAmountType(Integer amountType) {
        if (amountType >= 2000 && amountType < 3000) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 人工优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_ARTIFICIAL_OPERATOR = 21;
    /**
     * 师傅优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_ARTIFICIAL_MASTER = 22;
    /**
     * 会员优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_MEMBER = 23;
    /**
     * 优惠券优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_COUPON = 24;
    /**
     * 营销活动优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_ACTIVITY = 25;
    /**
     * 团购券优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_GROUP_COUPON = 26;

    /**
     * 渠道优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_CHANNEL = 31;

    /**
     * 渠道优惠券优惠
     */
    public final static int ORDER_IN_DISCOUNT_CATEG_CHANNEL_COUPON = 32;
}